# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@Author : Ayao
@Time   : 2022/5/21
@File   : 零矩阵.py
"""
from typing import List


class Solution:
    def setZeroes(self, matrix: List[List[int]]):
        """
        Do not return anything, modify matrix in-place instead.
        """
        # 最粗暴版本
        m, n = len(matrix[0]), len(matrix)
        tmpy, tmpx = [], []
        for y in range(n):
            for x in range(m):
                if matrix[y][x] == 0:
                    tmpy.append(y)
                    tmpx.append(x)
        for i in tmpy:
            matrix[i] = [0] * m
        for j in tmpx:
            for y in range(n):
                matrix[y][j] = 0
        return matrix

    def setZeroes2(self, matrix: List[List[int]]):
        m, n = len(matrix[0]), len(matrix)
        tmpy, tmpx = [False] * n, [False] * m
        for y in range(n):
            for x in range(m):
                if matrix[y][x] == 0:
                    tmpy[y] = tmpx[x] = True
        for y in range(n):
            for x in range(m):
                if tmpy[y] or tmpx[x]:
                    matrix[y][x] = 0
        return tmpy, tmpx


if __name__ == '__main__':
    a = [[15, 13, 0, 5],
         [14, 3, 1, 1],
         [12, 0, 8, 9],
         [16, 7, 10, 11]]

    temp = Solution().setZeroes2(a)
    print(temp)

    a1s = [[0, 0, 0, 0],
           [14, 3, 1, 1],
           [0, 0, 0, 0],
           [16, 7, 10, 11]]
